import { PetEquipBaseItem } from "./PetEquipBaseItem";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { ItemMenuRegister } from "../../common/menu/ItemMenuRegister";
import { Cache } from "../../../cache/Cache";
import { ShopOperType } from "../../shop/ShopOperType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { EPetEquipType } from "../../../../../Message/Public/EPetEquipType";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class PetEquipPanel
    
    export  class PetEquipPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._equipsVec = new Vector.<PetEquipBaseItem>();
            this._curEquips = [];
            this.createChildren();
            this.mouseEnabled = false;
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            var loc3=null;
            this.addChild(new GImageBitmap("PetEquipBg2.png"));
            var loc2=0;
            while (loc2 < 5) 
            {
                loc3 = new PetEquipBaseItem();
                loc1 = this.getXY(loc2);
                loc3.setSize(32, 32);
                loc3.x = loc1.x;
                loc3.y = loc1.y;
                loc3.toolTipData = HTMLUtil.addColor(Language.getString(61336), "#FFFFFF");
                loc3.doubleClickEnabled = true;
                this.addChild(loc3);
                loc3.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onEquipItemDoubleClick);
                this._equipsVec.push(loc3);
                ++loc2;
            }
            return;
        }

        /* internal  */onEquipItemDoubleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            ItemMenuRegister.hideOpList();
            if (!this._canOper || Cache.instance.shop.operType == ShopOperType.FIX) 
            {
                return;
            }
            var loc1=arg1.target as PetEquipBaseItem;
            if (loc1 && loc1.itemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipUndress, loc1.itemData));
            }
            return;
        }

        /* internal  */getXY(arg1: int): Object
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case 0:
                {
                    return {"x": 2, "y": 2};
                }
                case 1:
                {
                    return {"x": 61, "y": 2};
                }
                case 2:
                {
                    return {"x": 119, "y": 2};
                }
                case 3:
                {
                    return {"x": 179, "y": 2};
                }
                case 4:
                {
                    return {"x": 239, "y": 2};
                }
            }
            return {"x": 0, "y": 0};
        }

        public updateEquips(arg1: Array<any>, arg2: Boolean): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            this._canOper = arg2;
            if (this._curEquips.length == arg1.length) 
            {
                loc4 = 0;
                while (loc4 < arg1.length) 
                {
                    loc2 = this._curEquips[loc4] as ItemData;
                    loc3 = arg1[loc4] as ItemData;
                    if (!(loc2.data.uid == loc3.data.uid) || !(loc2.data.jsStr == loc3.data.jsStr) || !(loc2.data.itemCode == loc3.data.itemCode) || !(loc2.data.posType == loc3.data.posType)) 
                    {
                        break;
                    }
                    ++loc1;
                    ++loc4;
                }
                if (loc1 == arg1.length) 
                {
                    return;
                }
            }
            this._curEquips = [];
            this.clearEquips();
            if (arg1) 
            {
                loc7 = 0;
                while (loc7 < arg1.length) 
                {
                    loc6 = arg1[loc7] as ItemData;
                    (loc5 = this._equipsVec[this.getPosByType(loc6.type)]).itemData = loc6;
                    loc5.canOper = this._canOper;
                    this._curEquips.push(ItemsUtil.copyItemData(loc6));
                    ++loc7;
                }
            }
            return;
        }

        /* internal  */clearEquips(): void
        {
            var loc1=0;
            while (loc1 < this._equipsVec.length) 
            {
                this._equipsVec[loc1].itemData = null;
                ++loc1;
            }
            return;
        }

        /* internal  */getPosByType(arg1: int): int
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case EPetEquipType._EPetEquipWeapon:
                {
                    return 4;
                }
                case EPetEquipType._EPetEquipClothes:
                {
                    return 2;
                }
                case EPetEquipType._EPetEquipCollar:
                {
                    return 1;
                }
                case EPetEquipType._EPetEquipHelmet:
                {
                    return 0;
                }
                case EPetEquipType._EPetEquipJewelry:
                {
                    return 3;
                }
            }
            return 0;
        }

        /* internal */ /* var */_canOper: Boolean=false;

        /* internal */ /* var */_equipsVec: Vector.<PetEquipBaseItem>;

        /* internal */ /* var */_curEquips: Array<any>;
    }
